package com.example.demo.service.web;


import com.example.demo.entity.Article;
import com.example.demo.mapper.ArticleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ArticleService class
 *
 * @author yjq
 * @date 2018/7/30
 */
@Service
public class ArticleWebService {

    @Autowired
    private ArticleMapper articleMapper;


    /**
     * 查询所有文章
     *
     * @return Article
     * @author yjq
     */
    public List<Article> selectAll() {
        List<Article> list = articleMapper.selectAll();
        return list;
    }

    /**
     * 根据文章类型查询文章
     *
     * @return Article
     * @author yjq
     */
    public List<Article> selectByType(String articleType) {
        return articleMapper.selectByType(articleType);
    }

    /**
     * 根据文章标题查询文章
     *
     * @param articleTitle 文章标题
     * @return List<Article>
     * @author yjq
     */
    public List<Article> selectByArticleTitle(String articleTitle) {
        return articleMapper.selectByArticleTitle(articleTitle);
    }

    /**
     * 查询访问次数最多的7篇文章
     *
     * @return List<Article>
     * @author yjq
     */
    public List<Article> selectTop7() {
        return articleMapper.selectTop7();
    }

    /**
     * 查询最新的6篇聆听世界类型文章
     *
     * @return List<Article>
     * @author yjq
     */
    public List<Article> articleListenWorld6() {
        return articleMapper.articleListenWorld6();
    }

    /**
     * 根据id查询文章
     *
     * @param id 文章id
     * @return List<Article>
     * @author yjq
     */
    public Article selectById(Integer id) {
        articleMapper.updateReadTime(id);
        return articleMapper.selectById(id);
    }

    /**
     * 根据文章名称查询
     * @param name 文章名称
     * @return List<Article>
     */
    public List<Article> selectByName(String name) {
        return articleMapper.selectByName(name);
    }
}
